package com.bw.config;

import com.bw.domain.Channel;
import com.bw.service.ChannelService;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author bobo棒
 * @date 2024年07月08日 17:18
 */

@Configuration
public class BoolomUtils {


    @Autowired
    RedissonClient redissonClient;
    @Autowired
    ChannelService channelService;


    @Bean//把方法的返回值 示例化到spring容器
    public   RBloomFilter<String>   getBoolom(){
        RBloomFilter<String> channelname = redissonClient.getBloomFilter("channelname");
        channelname.tryInit(1000,0.03);
        //查询出数据库所有的栏目, 初始化到布隆过滤器中  --
        List<Channel> list = channelService.list();
        for (Channel channel : list) {
            channelname.add(channel.getName());
        }
        System.out.println("布隆过滤器初始化完成");
        return channelname;
    }
}
